package biz.obake.team.touchprotector.donation;

import android.app.Activity;
import android.os.Handler;
import biz.obake.team.android.b;
import com.android.billingclient.api.a;
import com.android.billingclient.api.f;
import com.android.billingclient.api.h;
import com.android.billingclient.api.i;
import com.android.billingclient.api.j;
import com.android.billingclient.api.l;
import com.android.billingclient.api.m;
import com.android.billingclient.api.n;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class a implements biz.obake.team.touchprotector.d.a, b.c {
    private static a i;
    /* access modifiers changed from: private */

    /* renamed from: b  reason: collision with root package name */
    public List<l> f1583b;

    /* renamed from: c  reason: collision with root package name */
    private final Runnable f1584c = new C0069a();
    /* access modifiers changed from: private */

    /* renamed from: d  reason: collision with root package name */
    public final n f1585d = new b();
    /* access modifiers changed from: private */
    public List<j> e;
    private final Runnable f = new c();
    private int g = 0;
    private Handler h = new Handler();

    /* renamed from: biz.obake.team.touchprotector.donation.a$a  reason: collision with other inner class name */
    class C0069a implements Runnable {
        C0069a() {
        }

        public void run() {
            ArrayList arrayList = new ArrayList();
            arrayList.add("donate.1");
            arrayList.add("donate.2");
            arrayList.add("donate.3");
            arrayList.add("donate.4");
            arrayList.add("donate.5");
            arrayList.add("donate_more.1");
            arrayList.add("donate_more.2");
            arrayList.add("donate_more.3");
            arrayList.add("donate_more.4");
            arrayList.add("donate_more.5");
            m.a c2 = m.c();
            c2.b(arrayList);
            c2.c("inapp");
            biz.obake.team.android.b.d().c().h(c2.a(), a.this.f1585d);
        }
    }

    class b implements n {
        b() {
        }

        public void a(com.android.billingclient.api.g gVar, List<l> list) {
            int a2 = gVar.a();
            if (a2 == -1) {
                biz.obake.team.android.b.d().h(b.d.Disconnected);
            } else if (a2 != 0) {
                biz.obake.team.android.b.d().h(b.d.Error);
                a.this.x("Error");
            } else {
                List unused = a.this.f1583b = list;
                a.this.y();
                a.this.u();
            }
        }
    }

    class c implements Runnable {
        c() {
        }

        public void run() {
            j.a g = biz.obake.team.android.b.d().c().g("inapp");
            int c2 = g.c();
            if (c2 == -1) {
                biz.obake.team.android.b.d().h(b.d.Disconnected);
            } else if (c2 != 0) {
                biz.obake.team.android.b.d().h(b.d.Error);
                a.this.x("Error");
            } else {
                List unused = a.this.e = g.b();
                a.this.n();
                a.this.o();
                a.this.z();
                if (a.this.e.size() != 0) {
                    return;
                }
            }
            a.this.w();
        }
    }

    class d implements Runnable {
        d() {
        }

        public void run() {
            a.this.u();
        }
    }

    class e implements com.android.billingclient.api.b {
        e(a aVar) {
        }

        public void a(com.android.billingclient.api.g gVar) {
        }
    }

    class f implements i {
        f(a aVar) {
        }

        public void a(com.android.billingclient.api.g gVar, String str) {
        }
    }

    static /* synthetic */ class g {

        /* renamed from: a  reason: collision with root package name */
        static final /* synthetic */ int[] f1590a;

        static {
            int[] iArr = new int[b.d.values().length];
            f1590a = iArr;
            try {
                iArr[b.d.Error.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
        }
    }

    /* access modifiers changed from: private */
    public void n() {
        for (j next : this.e) {
            if (next.e().startsWith("donate.") && 1 == next.b() && !next.f()) {
                a.C0095a c2 = com.android.billingclient.api.a.c();
                c2.b(next.c());
                biz.obake.team.android.b.d().c().a(c2.a(), new e(this));
            }
        }
    }

    /* access modifiers changed from: private */
    public void o() {
        for (j next : this.e) {
            if (next.e().startsWith("donate_more.")) {
                h.a c2 = h.c();
                c2.b(next.c());
                biz.obake.team.android.b.d().c().b(c2.a(), new f(this));
                return;
            }
        }
    }

    public static boolean p() {
        return "Donated".equals(biz.obake.team.touchprotector.g.c.c("Donation.Status"));
    }

    public static a q() {
        if (i == null) {
            i = new a();
        }
        return i;
    }

    public static void s(Map<String, String> map) {
        map.put("Donation.SkuChanged", "true");
        map.put("Donation.Status", "Unknown");
    }

    /* access modifiers changed from: private */
    public void u() {
        biz.obake.team.android.b.d().g(this.f);
    }

    /* access modifiers changed from: private */
    public void w() {
        int i2 = this.g;
        if (i2 < 20) {
            this.g = i2 + 1;
            this.h.postDelayed(new d(), 3000);
        }
    }

    /* access modifiers changed from: private */
    public void x(String str) {
        if (!str.equals(biz.obake.team.touchprotector.g.c.c("Donation.Status"))) {
            biz.obake.team.touchprotector.g.c.g("Donation.Status", str);
            biz.obake.team.touchprotector.log.a b2 = biz.obake.team.touchprotector.log.a.b();
            b2.d("DonationStatus: " + str);
        }
    }

    /* access modifiers changed from: private */
    public void y() {
        biz.obake.team.touchprotector.g.c.f("Donation.SkuChanged", true);
    }

    /* access modifiers changed from: private */
    public void z() {
        String str;
        Iterator<j> it = this.e.iterator();
        while (true) {
            if (!it.hasNext()) {
                str = "NotDonated";
                break;
            }
            j next = it.next();
            if (next.e().startsWith("donate.") && next.b() == 1) {
                str = "Donated";
                break;
            }
        }
        x(str);
    }

    public void a(com.android.billingclient.api.g gVar, List<j> list) {
        u();
    }

    public void b(b.d dVar) {
        if (g.f1590a[dVar.ordinal()] == 1) {
            x("Error");
        }
    }

    public List<l> r() {
        return this.f1583b;
    }

    public void start() {
        biz.obake.team.android.b.d().e(this);
        v();
    }

    public void stop() {
        biz.obake.team.android.b.d().l(this);
    }

    /* access modifiers changed from: package-private */
    public void t(l lVar, Activity activity) {
        f.a j = com.android.billingclient.api.f.j();
        j.b(lVar);
        int a2 = biz.obake.team.android.b.d().c().e(activity, j.a()).a();
        if (a2 == -1) {
            biz.obake.team.android.b.d().h(b.d.Disconnected);
        } else if (a2 != 0) {
            biz.obake.team.android.b.d().h(b.d.Error);
            x("Error");
        }
    }

    public void v() {
        biz.obake.team.android.b.d().g(this.f1584c);
    }
}
